<?php
/**
 * @function：多媒体信息管理接口
 * @Author: 倪银龙
 * @Mail niyinlong@126.com
 * @Date: 15-10-1
 * @Time: 上午9:00
 * @Blog: Http://www.thinkwechat.cn
 */
namespace wechat;
use wechat\accesstoken;
use wechat\curl;
/*
*素材管理
*临时素材管理和永久素材管理
*/
class media{
	/*
	*上传临时的素材文件
	*/
	public function upload($file, $type){
		$tool = new accesstoken();
		$token = $tool->getAccessToken();
		$queryUrl = 'https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token='.$token.'&type='.$type;
        $data = array();
        $data['media'] = '@'.$file;
        return curl::callWebServer($queryUrl, $data, 'POST', 1 , 0);
	}

	/*
	*下载临时的素材文件
	*/
	public function download($mediaid){
		$tool = new accesstoken();
		$token = $tool->getAccessToken();
		$queryUrl = 'https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token='.$token.'&media_id='.$mediaid;
        return curl::callWebServer($queryUrl, '', 'GET', 0);
	}
        
        /*
         * 更新部门
         */
        public function updateAllDept($mediaid) {
            $tool = new accesstoken();
            $token = $tool->getAccessToken();
            $queryUrl = 'https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty?access_token='.$token;
            $data = array();
            $data['media_id'] = $mediaid;
            $data['callback'] = array();
            return curl::callWebServer($queryUrl, $data, 'post',0, 0);
        }

}
?>